<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>
<%@ page import="com.limao.servlet.WebFunction" %>
<%@ page import="com.limao.DBDataClass.CrowdOrderDataClass" %>
<%@ page import="com.wsu.search.tools.Tools" %>
<%@ page import="com.limao.DBDataClass.CrowdSysProjectClass" %>
<%@ page import="com.limao.DBDataClass.CrowdUserAuthClass" %>

<%
    String orderid = Tools.RmNull(request.getParameter("orderid"));

    CrowdOrderDataClass cwdc = WebFunction.getCrowdOrderInfo(request, response, orderid);

    CrowdSysProjectClass crowd = WebFunction.getProjectInfo(cwdc.projectid);
    CrowdUserAuthClass user = WebFunction.getUserInfo(request, response);

%>

<html lang="en">
<head>

    <meta charset="UTF-8">
    <title>订单详情</title>

</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc cf f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
		      订单详情
    </div>
</div>

<div class="container jz mgt45">

    <%
        if (cwdc != null) {
            float freight = CacheClass.getFloatValue(cwdc.frieght);
            String freightStr = "免费";
            if (freight != 0) {
                freightStr = cwdc.frieght;
            }

            String goodimgurl = "";
            if (!TextUtils.isEmpty(crowd.projectimage)) {
                goodimgurl = crowd.projectimage.split(";")[0];
            }
    %>

    <section class="w100 bcf of">
        <div class="w92 jz of df mgt10 mgb10">
            <img src="<%=getImageBasePath(goodimgurl)%>" class="db hauto" style="width:100px;">
            <div class="mgl10">
                <p class="f15 c3"><%=cwdc.projectname%>
                </p>
                <div class="clearfix of">
                    <p class="f12 c9 fl"><span class="f12">&yen;</span><span class="f14"><%=cwdc.packageprice%></span>
                        ×<%=cwdc.ordernum%>
                    </p>
                    <p class="f13 cred fl" style="margin-left: 23px;"><span class="f12">&yen;</span><span
                            class="f14"><%=cwdc.totalrmb%></span></p>
                </div>
            </div>
        </div>
    </section>
    <section class="proSection pr w100 bcf of mgt10" style="box-shadow: 0 3px 7px #ddd;">
        <div class="detailCompany w92 jz mgt10 mgb10 c9 f13 lh18">
            <p>简介：<%=cwdc.intro %>
            </p>
            <p>数量：<span class="cred"><%=cwdc.ordernum%>件</span></p>
            <p>代理天数：<span class="cred"><%=cwdc.days%>天</span></p>
            <p>配送费：<span class="cred"><%=freightStr%></span></p>
        </div>
    </section>

	<section class="proSection pr w100 bcf mgt10 of" style="box-shadow: 0 3px 7px #ddd;">
	    <div class="orderDiv2 jz">
        <div class="f13 c9">
            <p class="mgt10">订单编号：<%=cwdc.order_sn%><span class="dib" style="width: 7%;"></span></p>
            <p class="mgt10">当前状态：<span
                    class="cred"><%=cwdc.stateAbout%></span>
            </p>
            <p class="mgt10">购买日期：<%=cwdc.ctimeAbout.split(" ")[0]%><span class="dib"
                                                                          style="width: 7%;"></span><%=cwdc.days%>
                天<span class="dib"
                        style="width: 7%;"></span></p>
            <p class="mgt10"> 支付方式：<%=cwdc.paytypeAbout%>
            </p>

            <%
                if (!TextUtils.isEmpty(cwdc.address) && cwdc.address.split("_").length > 2) {
            %>
            <p class="mgt10">收货地址：<%=cwdc.address.split("_")[0]%>
            </p>
            <p class="mgt10">收件人：<%=cwdc.address.split("_")[2]%>
            </p>
            <p class="mgt10">联系电话：<%=cwdc.address.split("_")[1]%>
            </p>
            <%
                }
            %>
            <div class="clearfix of mgt10">
                <div class="fl">
                    <p class="lh2">商品发售人：</p>
                </div>
                <div class="fl orderDivRight">
                    <p class="lh2"><%=cwdc.companyname%>
                    </p>
                    <p class="lh2"><%=cwdc.compaddress%>
                    </p>
                    <p class="lh2">联系：<%=cwdc.qq%>
                    </p>
                </div>
            </div>
            <%
                if (!TextUtils.isEmpty(cwdc.courier_sn)) {
            %>
            <p class="mgt10">物流信息：<span onclick="jumpToQeuryCourier(<%=cwdc.courier_url%>);"
                                        style="color: #5290F1"><%=cwdc.courier_sn.split("_")[0]%>&nbsp; <%=cwdc.courier_sn.split("_")[1]%></span>
            </p>
            <%
                }
            %>
        </div>
    </div>
	
	</section>
    <%
        }
    %>
</div><!--container-->
<div class="detailBottm pf w100 of">
    <%
        int state = -1;
        if (cwdc != null) {
            // state 订单状态/*0:取消 1：待付款 2：待发货 5：待收货 6：已完成 */
            String btnStr = "";
            state = CacheClass.getIntValue(cwdc.state);
            if(state == 1){%>
            	   	<button id="btncancel" onclick="btnCancelEvent();" class="fl cf f15 btnOrange"  style="width: 50%">取消   </button>
    				<button id="btnconfirm" onclick="btnConfirmEvent();" class="fl cf f15 btnBlue" style="width: 50%">付款</button>
             <%}else if(state == 5){%>
             	<button id="btnconfirm" onclick="btnConfirmEvent();" class="cf f15 btnBlue w100">签收</button>
             <%}%>

    <%
        }
    %>
</div>

<script>

    var state = <%=state%>;
/*     function judgeShowBtn() {
        if (state == -1) {
            return;
        } */
       

    function jumpToQeuryCourier(courierurl) {
        window.location.href = courierurl;
    }

    /**
     * 取消
     */
    function btnCancelEvent() {
        if (state * 1.0 == 1) {
            showTipDialog("提示", "您确定取消订单？", cancelO, 0);
        }
    }

    var cancelO = function cancelOrder() {
        $.ajax({
            url: "PlugServlet ",
            data: JSON.stringify({m: 1721, orderid: <%=cwdc.orderid%>}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
                if (data.state == 1) {
                    showToast("取消成功！");

                    // 存储需要刷新订单列表界面
                    localStorage.setItem("needrefreshmycrowdFunding", 'true');

                    setTimeout(function () {
                        history.back();
                    }, 500);
                } else {
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }

    function btnConfirmEvent() {
        if (state == 1) {
            payOrder();
        }  else if (state == 5) {
            confirmOrder();
        }

    }

    /**
     * 再次支付
     */
    function payOrder() {
        $.ajax({
            url: "PlugServlet ",
            data: JSON.stringify({m: 1722, orderid: <%=cwdc.orderid%>}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
                if (data.state == 1) {

                    // TODO: 再次支付
                    console.log("支付参数：" + data.params);

                } else {
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }

    /**
     * 确认收货
     */
    function confirmOrder() {
        $.ajax({
            url: "PlugServlet ",
            data: JSON.stringify({m: 1617, orderid: <%=orderid%>}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
                if (data.state == 1) {
                    showToast(data.info);

                    setTimeout(function () {
                        history.back();
                    }, 500);
                } else {
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }
    


</script>

</body>
</html>
